package com.api.user.controller;
import com.api.core.controller.Ctrl;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.user.model.Achievement;
import com.api.user.service.AchievementService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.List;
import com.api.core.annotation.PowerEnable;
import io.swagger.annotations.*;



/**
* Created by wanghuiwen on 2021/08/10.
*/
@PowerEnable(name = "achievement",url = "/achievement")
@Api(value = "achievement", tags = {"achievement"})
@RestController
@RequestMapping("/achievement")
public class AchievementController extends Ctrl{
    @Resource
    private AchievementService achievementService;

    @ApiOperation(value = "achievement添加", tags = {"achievement"}, notes = "achievement添加")
    @PostMapping(value="/add",name="achievement添加")
    public Result add(@ApiParam Achievement achievement) {
        if(achievement.getAchievementId()!=null){
            achievementService.save(achievement);
        }else {
            achievementService.save(achievement);
        }

        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "achievement删除", tags = {"achievement"}, notes = "achievement删除")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id",required=true, value = "achievementid", dataType = "Long", paramType = "query")
    })
    @PostMapping(value="/delete",name="achievement删除")
    public Result delete(@RequestParam Long id) {
        achievementService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "achievement列表信息", tags = {"achievement"}, notes = "achievement列表信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "page", value = "页码", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "size", value = "每页显示的条数", dataType = "String", paramType = "query", defaultValue = "10")
    })
    @PostMapping(value = "/all", name = "achievement列表信息")
    public Result list(@RequestParam(defaultValue = "0") Integer page,
                       @RequestParam(defaultValue = "10") Integer size,
                       Authentication authentication) {

        return achievementService.all(page, size,getAuthUser(authentication).getId());
    }

    @ApiOperation(value = "achievement列表信息", tags = {"achievement"}, notes = "achievement列表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页显示的条数", dataType = "String", paramType = "query", defaultValue = "10")
    })
    @PostMapping(value = "/my", name = "achievement列表信息")
    public Result my(@RequestParam(defaultValue = "0") Integer page,
                       @RequestParam(defaultValue = "10") Integer size,
                       Authentication authentication) {

        return achievementService.my(page, size,getAuthUser(authentication).getId());
    }

    @PostMapping(value = "/addsetp", name = "achievement列表信息")
    public Result my(Long achievementId,Long userId,Integer step) {
        return achievementService.addStep(achievementId,userId,step);
    }
}
